import xlsx from 'node-xlsx';
import { fileURLToPath,pathToFileURL } from 'url';
import {dirname} from "path";

const excel = {
  reader: (filePath) => {
    return xlsx.parse(filePath, {cellDates: true});
  },
  /*
  * @Params data格式为:
  * [
  *   {name: 'sheet1', data: [[1, 2, 3], [4, 5, 6]]},
  *  {name: 'sheet2', data: [[7, 8, 9], [10, 11, 12]]},
  *   .....
  * ]
  *
  * */
  writer: (data) => {
    return xlsx.build(data);
  },
  downloader(ctx, data = [], fileName = 'default.xlsx') {
    ctx.set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    ctx.set('content-Disposition', `attachment; filename=${fileName}`);
    return this.writer(data);
  }
}
const pathUtil = {

}


export {
  excel,
  pathUtil,
}